package com.douma.第26天;

import java.util.Scanner;

/**
 * 抖码算法，让算法学习变的简单有趣
 *
 * @作者 : 老汤
 */
public class 五键键盘的输出 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String[] s = sc.nextLine().split(" ");

        String temp = ""; // 剪贴板
        String screen = ""; // 屏幕
        String select = ""; // 选择的

        for (int i = 0; i < s.length; i++) {

            switch (s[i]) {
                case "1":   // a 键在屏幕上输出一个字母 a
                    if (select != "") {
                        screen = "a";
                        select = "";
                    } else {
                        screen += "a";
                    }
                    break;
                case "2":   // ctrl-c 将当前选择的字母复制到剪切板
                    if (select != "") {
                        temp = select;
                    }
                    break;
                case "3":   // ctrl-x 将当前选择的字母复制到剪贴板，并清空选择的字母
                    if (select != "") {
                        temp = select;
                        screen = "";
                        select = "";
                    }
                    break;
                case "4":   // ctrl-v 将当前剪切板里的字母输出到屏幕
                    if (select != "") {
                        screen = temp;
                        select = "";
                    } else {
                        screen += temp;
                    }
                    break;
                case "5": // ctrl-a 选择当前屏幕上的所有字母
                    if (screen != "") {
                        select = screen;
                    }
                    break;
            }
        }

        System.out.println(screen.length());
    }
}
